package com.cb.controller;

import com.alipay.api.AlipayApiException;
import com.cb.dao.AlipayDao;
import com.cb.pojo.OrderList;
import com.cb.pojo.ScreeninFormation;
import com.cb.service.AlipayService;
import com.cb.service.UserFilmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.filter.CorsFilter;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.HashMap;

@RestController
@RequestMapping("/userfilm")
@Api(value = "用户对电影的操作", description = "用户对电影的操作")
public class UserFilmController {

    @Autowired
    UserFilmService userFilmService;
    @Autowired
    CorsFilter corsFilter;
    @Autowired
    AlipayService alipayService;
    @Autowired
    AlipayDao alipayDao;

    /**
     * 查找所有的电影
     * @return
     */
    @PostMapping("/selectfilm")
    @ApiOperation(value = "查询所有的电影", notes = "查询所有的电影")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码"),
    })
    public String selectFilm(@RequestBody HashMap json, HttpServletRequest request){
        return userFilmService.selectFilm(json,request);
    }


    /**
     * 热映：页面上面点击国家，类型，年份进行筛选。
     * @param json
     * @return
     */
    @PostMapping("/hotShowFilmother")
    @ApiOperation(value = "热映：页面上面点击国家，类型，年份进行筛选", notes = "页面上面点击国家，类型，年份进行筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activeName", value = "查询的类型，一般为hot，comingsoon，classic"),
            @ApiImplicitParam(name = "countries", value = "国家"),
            @ApiImplicitParam(name = "type", value = "类型"),
            @ApiImplicitParam(name = "markettime", value = "上映时间"),
            @ApiImplicitParam(name = "page", value = "页码")
    })
    public String hotShowFilmother(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        String activeName = String.valueOf(json.get("activeName"));
        String countries = String.valueOf(json.get("countries"));
        String type = String.valueOf(json.get("type"));
        String markettime=String.valueOf(json.get("markettime"));
        String pag=String.valueOf(json.get("page"));
        int page = Integer.parseInt(pag);
        return userFilmService.selectFilmother(activeName,countries,type,markettime,page,request);
    }

    /**
     * 经典：页面上面点击国家，类型，年份进行筛选。
     * @param json
     * @return
     */
    @PostMapping("/selectfilmother")
    @ApiOperation(value = "经典：页面上面点击国家，类型，年份进行筛选", notes = "页面上面点击国家，类型，年份进行筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activeName", value = "查询的类型，一般为hot，comingsoon，classic"),
            @ApiImplicitParam(name = "countries", value = "国家"),
            @ApiImplicitParam(name = "type", value = "类型"),
            @ApiImplicitParam(name = "markettime", value = "上映时间"),
            @ApiImplicitParam(name = "page", value = "页码")
    })
    public String selectFilmother(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        String activeName = String.valueOf(json.get("activeName"));
        String countries = String.valueOf(json.get("countries"));
        String type = String.valueOf(json.get("type"));
        String markettime=String.valueOf(json.get("markettime"));
        String pag=String.valueOf(json.get("page"));
        int page = Integer.parseInt(pag);
        return userFilmService.selectFilmother(activeName,countries,type,markettime,page,request);
    }

    /**
     * 即将：页面上面点击国家，类型，年份进行筛选。
     * @param json
     * @return
     */
    @PostMapping("/selectComingSoonFilmother")
    @ApiOperation(value = "即将：页面上面点击国家，类型，年份进行筛选", notes = "页面上面点击国家，类型，年份进行筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activeName", value = "查询的类型，一般为hot，comingsoon，classic"),
            @ApiImplicitParam(name = "countries", value = "国家"),
            @ApiImplicitParam(name = "type", value = "类型"),
            @ApiImplicitParam(name = "markettime", value = "上映时间"),
            @ApiImplicitParam(name = "page", value = "页码")
    })
    public String selectComingSoonFilmother(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        String activeName = String.valueOf(json.get("activeName"));
        String countries = String.valueOf(json.get("countries"));
        String type = String.valueOf(json.get("type"));
        String markettime=String.valueOf(json.get("markettime"));
        String pag=String.valueOf(json.get("page"));
        int page = Integer.parseInt(pag);
        return userFilmService.selectFilmother(activeName,countries,type,markettime,page,request);
    }

    /**
     * 按照名字进行模糊筛选
     * @param json
     * @return
     */
    @PostMapping("/selectname")
    @ApiOperation(value = "按照影片名字进行模糊筛选", notes = "按照影片名字进行模糊筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "模糊查询名字")
    })
    public String selectFilmName(@RequestBody HashMap json,HttpServletRequest request){
        String name = String.valueOf(json.get("name"));
        return userFilmService.selectFilmName(name,request);
    }

    /**
     * 点进去电影，查看电影
     * @param
     * @return
     */
    @PostMapping("/selectFilmDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "影片编号"),
    })
    @ApiOperation(value = "点进去电影，查看电影", notes = "点进去电影，查看电影")
    public String selectFilmDetail(@RequestBody HashMap json,HttpServletRequest request){
        String id = String.valueOf(json.get("id"));
        return userFilmService.selectFilmDetail(id,request);
    }

    /**
     * 预定
     * @param json
     * @param request
     * @return
     * @throws ParseException
     */
    @PostMapping("/Scheduled")
    @ResponseBody
    @ApiOperation(value = "预定", notes = "预定")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyid", value = "影院id"),
            @ApiImplicitParam(name = "yyname", value = "影院名字"),
            @ApiImplicitParam(name = "ypid", value = "影片id"),
            @ApiImplicitParam(name = "ypname", value = "影片名字"),
            @ApiImplicitParam(name = "ccid", value = "场次"),
            @ApiImplicitParam(name = "username", value = "帐号"),
            @ApiImplicitParam(name = "name", value = "用户名字"),
            @ApiImplicitParam(name = "price", value = "价格"),
            @ApiImplicitParam(name = "tfvip", value = "是否会员"),
            @ApiImplicitParam(name = "status", value = "状态"),
            @ApiImplicitParam(name = "locate", value = "座位：几行几列")
    })
    public String scheduled(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return alipayService.scheduled(json,request);
    }
    /**
     * 支付
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("/filmply")
    @ResponseBody
    @ApiOperation(value = "支付", notes = "支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ddid", value = "订单编号")
    })
    public String filmPly(@RequestBody HashMap json,HttpServletRequest request) throws AlipayApiException, ParseException {
        return alipayService.filmPly(json,request);
    }

    /**
     * 根据时间还有用户地点以及用户想看的电影筛选影院
     * @param json
     * @return
     * @throws ParseException
     */
    @PostMapping("/selectFilmcityandCinema")
    @ApiOperation(value = "根据时间还有用户地点以及用户想看的电影筛选影院", notes = "根据时间还有用户地点以及用户想看的电影筛选影院")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ypid", value = "影院id"),
            @ApiImplicitParam(name = "ctiy", value = "城市")

    })
    @ResponseBody
    public String selectFilmcityandCinema(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return userFilmService.selectFilmcityandCinema(json,request);
    }

    /**
     *添加影评
     * @param json
     * @return
     * @throws ParseException
     */
    @PostMapping("/insertfilmevaluation")
    @ResponseBody
    @ApiOperation(value = "添加影评", notes = "添加影评")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ypid", value = "影片id"),
            @ApiImplicitParam(name = "score", value = "分数"),
            @ApiImplicitParam(name = "name", value = "片名"),
            @ApiImplicitParam(name = "username", value = "用户帐号"),
            @ApiImplicitParam(name = "comment", value = "评论内容")
    })
    public String insertFilmeValuation(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return userFilmService.insertFilmeValuation(json,request);
    }

    /**
     * 通过改变定位在页面显示不同的影院
     * @param json
     * @param request
     * @return
     */
    @PostMapping("/selectcitycinema")
    @ResponseBody
    @ApiOperation(value = "通过改变定位在页面显示不同的影院", notes = "通过改变定位在页面显示不同的影院")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "城市"),
    })
    public String selectCityCinema(@RequestBody HashMap json ,HttpServletRequest request){
        return userFilmService.selectCityCinema(json,request);
    }

    /**
     * 已经确认定位下对影院做搜索
     * @param json
     * @param request
     * @return
     */
    @PostMapping("/selectcitycinemaname")
    @ResponseBody
    @ApiOperation(value = "已经确认定位下对影院做搜索", notes = "已经确认定位下对影院做搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ctiy", value = "城市"),
            @ApiImplicitParam(name = "yyname", value = "影院名字"),
    })
    public String selectCityCinemaName(@RequestBody HashMap json ,HttpServletRequest request){
        return userFilmService.selectCityCinemaName(json,request);
    }

    /**
     * 支付测试
     * @param
     * @return
     * @throws AlipayApiException
     */
    @GetMapping("/zfcs")
    @ApiOperation(value = "支付测试", notes = "支付测试")
    public String zfcs() throws AlipayApiException {
        return alipayService.zhiFu("11111","你好","65","电影","2m","code");
    }

    /**
     * 退款测试，得先支付
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("refundcs")
    @ApiOperation(value = "退款测试，得先支付", notes = "退款测试，得先支付")
    public String refundcs() throws AlipayApiException {
        return userFilmService.refund("111",65,1.0);
    }

    /**
     * 退款
     * @param json
     * @param request
     * @return
     * @throws ParseException
     * @throws AlipayApiException
     */
    @PostMapping("/refund")
    @ResponseBody
    @ApiOperation(value = "退款", notes = "退款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ddid", value = "订单编号")
    })
    public String refund(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.userrefund(json,request);
    }

    /**
     * 点进去一个影院，查看这个影院这个时间之后的放映安排
     * @param json
     * @param request
     * @return
     * @throws ParseException
     */
    @PostMapping("/yyidselectsi")
    @ResponseBody
    @ApiOperation(value = "点进去影院查看影院的安排", notes = "点进去影院查看影院的安排")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyid", value = "影院id"),
            @ApiImplicitParam(name = "ypid", value = "影片id")
    })
    public String yyidSelectsi(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return userFilmService.yyidSelectsi(json,request);
    }

    /**
     * 在订单处点击改签得按钮判断是不是能改签
     * @param json
     * @param request
     * @return
     * @throws ParseException
     */
    @PostMapping("/changeorder")
    @ResponseBody
    @ApiOperation(value = "改签", notes = "改签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ddid", value = "订单id")
    })
    public String changeOrder(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return userFilmService.changeOrder(json,request);
    }

    @PostMapping("/qrchangeorder")
    @ResponseBody
    @ApiOperation(value = "改签", notes = "改签")
    public String qrChangeOrder(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.qrChangeOrder(json,request);
    }

    @PostMapping("/filmeValuationLimit")
    @ResponseBody
    @ApiOperation(value = "获取某个影片的评论", notes = "获取某个影片的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ypid", value = "影片id"),
            @ApiImplicitParam(name = "page", value = "页码"),
    })
    public String filmeValuationLimit(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.filmeValuationLimit(json,request);
    }

    @PostMapping("/filmeScore")
    @ResponseBody
    @ApiOperation(value = "获取某个影片的分数", notes = "获取某个影片的分数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ypid", value = "影片id"),
            @ApiImplicitParam(name = "page", value = "页码"),
    })
    public String filmeScore(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.filmeScore(json,request);
    }

    @PostMapping("/filmeDetails")
    @ResponseBody
    @ApiOperation(value = "获取某个影院详情", notes = "获取某个影院详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yyid", value = "影院id")
    })
    public String filmeDetails(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.cinemaDetails(json,request);
    }

    @PostMapping("/filmeSeatDetails")
    @ResponseBody
    @ApiOperation(value = "获取某个场次的座位信息", notes = "获取某个场次的座位信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场次信息id：screeninformation")
    })
    public String filmeSeatDetails(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.filmeSeatDetails(json,request);
    }

    @PostMapping("/SeatTest")
    @ResponseBody
    @ApiOperation(value = "座位测试", notes = "座位测试")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场次信息id：screeninformation")
    })
    public String SeatTest(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return userFilmService.SeatTest(json,request);
    }

    @GetMapping("/tet")
    public void tet(){
        ScreeninFormation screeninFormation = alipayDao.selectscreeninFormation("2");
        System.out.println(screeninFormation.getYyid()+"   "+screeninFormation.getNumberid());
        int number = alipayDao.selectnumber(screeninFormation.getYyid(),screeninFormation.getNumberid());
        System.out.println(number);
    }
}
